using System;
using Gtk;
using Jandaya.Framework.Dialogs;

namespace Jandaya.Client.Windows
{
	public partial class MainWindow : Gtk.Window
	{
		private const string ST_QUIT_QUESTION = "Deseja realmente sair do sistema?";
		
		public MainWindow () : base(Gtk.WindowType.Toplevel)
		{
			this.Build ();
		}
		
		
		protected override void OnDestroyed ()
		{
			base.OnDestroyed ();
			if (App.Authentication.SessionUser != null){
				Gtk.Application.Quit();
			}
		}
		
		protected override void OnShown ()
		{
			base.OnShown ();			
			lblUsuario.Text =  string.Format("<b>Usuário</b>: {0}", App.Authentication.SessionUser.Nome);
			lblUsuario.UseMarkup = true;
			
			App.Manager.Empresa.LoadDefault();
			lblEmpresa.Text = string.Format("<b>Empresa</b>: {0} - {1}  ", App.Manager.Empresa.Nome, App.Manager.Empresa.CNPJ);
			lblEmpresa.UseMarkup = true;	
			
		}
				
		
		protected virtual void QuitActionActivated (object sender, System.EventArgs e)
		{
			if (MsgDialog.ShowQuestion(ST_QUIT_QUESTION) == ResponseType.Yes)
				this.Destroy();
		}
		
		protected virtual void LogoutActionActivated (object sender, System.EventArgs e)
		{
			if (MsgDialog.ShowQuestion(string.Format("Deseja realmente finalizar a sessão do usuário '{0}'?", 
			                                         App.Authentication.SessionUser.Nome)) == ResponseType.Yes){
				App.Authentication.LogOut();
				App.LoginDialog.Show();				
				this.Destroy();
			}
		}
		
		protected virtual void OnAboutActivated (object sender, System.EventArgs e)
		{
			AboutDialog about = new AboutDialog();
			about.ProgramName = "Jandaya - Sistema de Gestão";
			about.Version = "0.0.1";
			about.Run();
			about.Destroy();
		}
		
		protected virtual void OnConfigActivated (object sender, System.EventArgs e)
		{					
			dlgConfigDataBase dlg = new dlgConfigDataBase();		
			dlg.Run();
			dlg.Destroy();
		}
		
		protected virtual void OnConfigConnectionActivated (object sender, System.EventArgs e)
		{
			dlgConfigDataBase dlg = new dlgConfigDataBase();
			dlg.Run();
			dlg.Destroy();
		}
		
		protected virtual void OnQuitActiveted (object sender, System.EventArgs e)
		{
			if (MsgDialog.ShowQuestion("Deseja realmente sair do sistema?") == ResponseType.Yes){			
				Application.Quit();
			}
		}
		
		protected virtual void OnCadEmpresaActivated (object sender, System.EventArgs e)
		{
			wndCadEmpresa wnd = new wndCadEmpresa();			
			wnd.Show();			
		}
		
		protected virtual void OnCadProjetosActivated (object sender, System.EventArgs e)
		{
			wndCadProjeto wnd = new wndCadProjeto();
			wnd.Show();			
		}
		
		
		
		
		
		
		
		
				
		
	}
}

